﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Xml.Linq;
using System.Web.UI.WebControls;

namespace com.codeplex.eatoutadvocate.Web.Service
{
    public partial class Get : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // CHECK KEY FIRST, <which is the facebook token>

            string getRestaurants = Request.QueryString["restaurant"];
            if (getRestaurants == "true")
            {
                XElement restaurants = GetRestaurants();
                //string restaurantXML = restaurants.ToString();
                HttpContext.Current.Response.Write(restaurants);
            }

            string getEatOuts = Request.QueryString["eatouts"];
            if (getEatOuts == "true")
            {
                string user = Request.QueryString["user"];
                XElement eatouts = GetEatOuts();
                HttpContext.Current.Response.Write(eatouts);
            }
        }

        protected XElement GetRestaurants()
        {
            BL.DataLogic dataLogic = new BL.DataLogic();
            List<string> restaurants = dataLogic.GetRestaurants();
            XNamespace xn = "http://eatoutadvocate.codeplex.com/";
            XElement xelement = new XElement(xn + "Get");
            foreach (string restaurant in restaurants)
            {
                xelement.Add(new XElement("restaurant", new XAttribute("name",restaurant)));
            }

            //xdoc.Declaration = new XDeclaration("1.0", "utf-8", null);
            return xelement;
            
        }
        
        protected XElement GetEatOuts()
        {
            return null;
        }
    }
}